package com.party.web.biz.information;

import com.party.core.model.information.Information;
import com.party.core.model.information.InformationType;
import com.party.core.model.information.InformationTypeGenre;
import com.party.core.service.information.IInformationService;
import com.party.core.service.information.IInformationTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName InformationBizService
 * @Description
 * @Author shenliuhai
 * @Date 2020/2/18 11:51
 **/
@Service
public class InformationBizService {

    @Autowired
    private IInformationTypeService informationTypeService;
    @Autowired
    private IInformationService informationService;


    public boolean isMutualOrJoinType(Information information) {
        information.setDelFlag(Information.DEL_FLAG_NORMAL);
        InformationType type = new InformationType();
        type.setCategory(InformationTypeGenre.INFORMATIONTYPE_CATEGORY_MUTUAL.getCode());
        List<InformationType> mutualList = informationTypeService.list(type);
        InformationType mutualType = null;
        if (mutualList.size() > 0) {
            mutualType = mutualList.get(0);
        }
        //是否存在联系类型
        type.setCategory(InformationTypeGenre.INFORMATIONTYPE_CATEGORY_JOIN.getCode());
        List<InformationType> joinList = informationTypeService.list(type);
        InformationType joinType = null;
        if (joinList.size() > 0) {
            joinType = joinList.get(0);
        }

        if (mutualType != null && mutualType.getId().equals(information.getInformationTypeId())) {
            List<Information> list = informationService.list(information);
            if (list.size() > 0) {
                return false;
            }

        }

        if (joinType != null && joinType.getId().equals(information.getInformationTypeId())) {
            List<Information> list = informationService.list(information);
            if (list.size() > 0) {
                return false;
            }
        }

        return true;
    }
}
